# config/database.py
import pymysql
from src.utils.exceptions import DatabaseConnectionError

class DatabaseConfig:
    def __init__(self):
        self.host = 'localhost'
        self.port = 3306
        self.user = 'root'
        self.password = 'YanLeLe0010MiQ!'
        self.database = 'kss-zixun-db'
        self.charset = 'utf8mb4'

    def get_connection(self):
        """获取数据库连接"""
        try:
            connection = pymysql.connect(
                host=self.host,
                port=self.port,
                user=self.user,
                password=self.password,
                database=self.database,
                charset=self.charset,
                cursorclass=pymysql.cursors.DictCursor
            )
            return connection
        except Exception as e:
            raise DatabaseConnectionError(f"数据库连接失败: {str(e)}")
